#!/bin/sh

if [ $# -ne 1 ]; then
	echo "Usage: $0 诗人名字（如李白，仅限唐朝）."
	exit
fi

mdfile=~/workshop/gitee/books/全唐诗.md

awk '{printf $0 "XXXX" }' $mdfile | sed -e "s/XXXX#### /XXXX\n#### /g" |grep "诗人: "$1  >tmp.md

counterofshi=`wc tmp.md|awk '{print $1}'`

echo "### "$1"全集" > $1全集.md
echo "" >> $1全集.md

echo "<strong>《"$1"全集》 共" $counterofshi "首（取自《全唐诗》)</strong>"  >> $1全集.md
echo "" >> $1全集.md

cat tmp.md| sed -e "s/XXXX/\n/g" |sed -e "s/卷.*【/【/g">>$1全集.md

rm -f tmp.md
